package cn.zwk.excel;

import java.util.List;

/**
 * 解析配置：指定关键列与语句列，并定义跳过策略。
 */
public final class ParseOptions {
    private final String sheetName; // 允许为 null 表示第一个Sheet
    private final int headerRowIndex; // 0-based，表头所在行
    private final ColumnSelector keyColumn;
    private final List<ColumnSelector> statementColumns;
    private final boolean skipMergedCells; // 默认 true
    private final boolean skipEmptyKeyRows; // 默认 true

    private ParseOptions(Builder b) {
        this.sheetName = b.sheetName;
        this.headerRowIndex = b.headerRowIndex;
        this.keyColumn = b.keyColumn;
        this.statementColumns = List.copyOf(b.statementColumns);
        this.skipMergedCells = b.skipMergedCells;
        this.skipEmptyKeyRows = b.skipEmptyKeyRows;
    }

    public String sheetName() { return sheetName; }
    public int headerRowIndex() { return headerRowIndex; }
    public ColumnSelector keyColumn() { return keyColumn; }
    public List<ColumnSelector> statementColumns() { return statementColumns; }
    public boolean skipMergedCells() { return skipMergedCells; }
    public boolean skipEmptyKeyRows() { return skipEmptyKeyRows; }

    public static Builder builder() { return new Builder(); }

    public static final class Builder {
        private String sheetName;
        private int headerRowIndex = 0;
        private ColumnSelector keyColumn;
        private List<ColumnSelector> statementColumns = List.of();
        private boolean skipMergedCells = true;
        private boolean skipEmptyKeyRows = true;

        public Builder sheetName(String sheetName) { this.sheetName = sheetName; return this; }
        public Builder headerRowIndex(int headerRowIndex) { this.headerRowIndex = headerRowIndex; return this; }
        public Builder keyColumn(ColumnSelector keyColumn) { this.keyColumn = keyColumn; return this; }
        public Builder statementColumns(List<ColumnSelector> statementColumns) { this.statementColumns = statementColumns; return this; }
        public Builder skipMergedCells(boolean skipMergedCells) { this.skipMergedCells = skipMergedCells; return this; }
        public Builder skipEmptyKeyRows(boolean skipEmptyKeyRows) { this.skipEmptyKeyRows = skipEmptyKeyRows; return this; }

        public ParseOptions build() { return new ParseOptions(this); }
    }
}

